package com.hibernate.rcache.region;

import com.rcache.core.cache.Rcache;
import com.rcache.core.manager.CacheManager;
import org.hibernate.cache.CacheException;
import org.hibernate.cache.QueryResultsRegion;
import org.hibernate.cache.Timestamper;
import org.hibernate.cfg.Settings;

import java.util.Map;
import java.util.Properties;

public class RcacheQueryResultsRegion implements QueryResultsRegion {
    private CacheManager cacheManager;
    private Rcache cache;
    private Settings settings;
    private Properties properties;

    public RcacheQueryResultsRegion(CacheManager cacheManager, Rcache cache, Settings settings, Properties properties) {
        this.cacheManager = cacheManager;
        this.cache = cache;
        this.settings = settings;
        this.properties = properties;


    }

    public Object get(Object key) throws CacheException {

        return cache.get(key).getObjectValue();
    }

    public void put(Object key, Object value) throws CacheException {

        cache.put(key,value);
    }

    public void evict(Object key) throws CacheException {
        System.out.println(123);
      cache.remove(key);
    }

    public void evictAll() throws CacheException {
        System.out.println(123);
        cache.clear();
    }

    public String getName() {

        return cache.getCacheName();
    }

    public void destroy() throws CacheException {
        cacheManager.remove(cache.getCacheName());

    }

    public boolean contains(Object key) {
        return cache.containsKey(key);
    }

    public long getSizeInMemory() {
        return cacheManager.getSizeInMemory();
    }

    public long getElementCountInMemory() {
        return cacheManager.getElementCountInMemory();
    }

    public long getElementCountOnDisk() {
        return cache.getDiskCacheSize();
    }

    public Map toMap() {
        return cache.toMap();
    }

    public long nextTimestamp() {
        return Timestamper.next();
    }

    public int getTimeout() {
        return cacheManager.getTimeout();
    }
}
